﻿//***********************************************************************
 //* Module:  TbBstBreakRoleRecDAL
// * 作者:  曹荣芝
 //* Modified: 2013-03-25
// * Purpose: Definition of the Class TbBstBreakRoleRecDAL
// ***********************************************************************/
using System;
using System.Data;
using XWG.JWBST;
using XWG.JWBST.JWBSTEntity;
using XWG.Framework.AuthSPConst;
using XWG.Framework.AuthUtility;
using XWG.JWBST.JWBSTSPConst;
using XWG;
using XWG.Framework.MSException;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using System.Data.OracleClient;
namespace XWG.JWBST.JWBSTDAL
{
	/// <summary>
	/// 
	/// </summary>
	public class TbBstBreakRoleRecDAL
	{
        #region 删除操作
                /// <summary>
        /// 删除。
        /// </summary>
        /// <param name="carpkid">要删除的的主键值。</param>
        /// <param name="userid">操作员。</param>
        /// <param name="isLog">是否写入日志。</param>
        /// <returns>是否成功 1 表示成功 负值代表失败</returns>
        public static ResultModel Delete(object carpkid,object userid,bool isLog)
        {
            ResultModel resultModel = new ResultModel();//定义错误信息类
            try
            {
                //载入实例
                 JWBSTEntity.TbBstBreakRoleRec u = JWBSTDAL.TbBstBreakRoleRecDAL.Load(carpkid) as JWBSTEntity.TbBstBreakRoleRec;
             
                if (isLog)//如果写入日志
                {
                    //AppLog log = new AppLog();
                    //log.UserId = Convert.ToString(userid);
                    //log.Id = System.Guid.NewGuid().ToString();
                    //log.LogContent = "删除";
                    //log.LogObject = TbBstBreakRoleRecConst.TableName;
                    //log.LogType = "操作日志";
                    //log.Opratetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    //Db.TransDelete<TbBstBreakRoleRec, AppLog>(u, log);
                }
                else//不写入日志
                {
                Db.TransDelete(u);
                }
                resultModel.ErrorCode = 0;
                resultModel.FiledKey = Convert.ToString(carpkid);
                resultModel.ISSucceed = true;
                return resultModel;     
            }
            catch (Exception ex)
            {

                resultModel.ErrorCode = -9994;
                resultModel.FiledKey = Convert.ToString(carpkid);
                resultModel.ISSucceed = false;
                MSEx.DealErr(ex, "实体类的删除操作");
                return resultModel;
                
            }
        }
        #endregion
        #region 根据主键查询一条记录
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="carpkid">主键</param>
        /// <returns>用户实体</returns>
        public static JWBSTEntity.TbBstBreakRoleRec Load(object carpkid)
        {
              return Db.GetModel<JWBSTEntity.TbBstBreakRoleRec>(carpkid); 
        }
        #endregion     
        #region 查询操作
       /// <summary>
        /// 查询
        /// </summary>
        public static IList<TbBstBreakRoleRec> SelectList()
        {
            try
            {
                ICriteria crt = Db.Session.CreateCriteria(typeof(TbBstBreakRoleRec));
                IList<TbBstBreakRoleRec> list = crt.List<TbBstBreakRoleRec>();
                return list;
            }
            catch (Exception ex)
            {
                XWG.Framework.MSException.MSEx.DealErr(ex, "查询");
                return null;
            }
            finally
            {
                
            }
        }
        #endregion
        #region 插入操作
        /// <summary>
        /// 新增。
        /// </summary>
        /// <param name="info">待新增的信息。</param>
        /// <param name="userid">操作员。</param>
        /// <param name="isLog">是否写入日志。</param>
        /// <returns>新增是否成功的标示。（1：成功；负值失败）</returns>
        public static ResultModel Insert(JWBSTEntity.TbBstBreakRoleRec info, object userid, bool isLog)
        {
            ResultModel resultModel = new ResultModel();
            object filedkey;
            try
            {
                if (isLog)
                {
                    
                    //AppLog log = new AppLog();
                    //log.UserId = Convert.ToString(userid);
                    //log.Id = System.Guid.NewGuid().ToString();
                    //log.LogContent = "新建";
                    //log.LogObject = TbBstBreakRoleRecConst.TableName;
                    //log.LogType = "操作日志";
                    //log.Opratetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    //filedkey= Db.TransInsert<TbBstBreakRoleRec,AppLog>(info,log);
                }
                else
                {
                   filedkey=  Db.TransInsert<TbBstBreakRoleRec>(info);
                }
                 resultModel.ErrorCode = 0;
                //resultModel.FiledKey = Convert.ToString(filedkey);
                resultModel.ISSucceed = true;
                return resultModel;
            }
            catch (Exception ex)
            {

                resultModel.ErrorCode = -9998;
                resultModel.FiledKey = "";
                resultModel.ISSucceed = false;
                MSEx.DealErr(ex, "实体类的插入操作");
                return resultModel;
            }   
        }
		#endregion         
        #region 修改操作
        /// <summary>
        /// 修改。
        /// </summary>
        /// <param name="info">待修改的信息。</param>
        /// <param name="userid">操作员。</param>
        /// <param name="isLog">是否写入日志。</param>
        /// <returns>修改是否成功的标示。（1：成功；负值失败）</returns>
        public static ResultModel Update(JWBSTEntity.TbBstBreakRoleRec info, object userid, bool isLog)
        {
            ResultModel resultModel = new ResultModel();
            try
            {
                 if (isLog)
                {
                     
                    
                    //AppLog log = new AppLog();
                    //log.UserId = Convert.ToString(userid);
                    //log.Id = System.Guid.NewGuid().ToString();
                    //log.LogContent = "修改";
                    //log.LogObject = TbBstBreakRoleRecConst.TableName;
                    //log.LogType = "操作日志";
                    //log.Opratetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    //Db.TransUpdate<TbBstBreakRoleRec, AppLog>(info, log);
                }
                else
                {
                  Db.TransUpdate<TbBstBreakRoleRec>(info);
                }
                resultModel.ErrorCode = 0;
                 resultModel.FiledKey = "";
                 resultModel.ISSucceed = true;
                 return resultModel;
            }
            catch (Exception ex)
            {
              resultModel.ErrorCode = -9997;
                resultModel.FiledKey = "";
                resultModel.ISSucceed = false;
              MSEx.DealErr(ex, "实体类的修改操作");
              return resultModel;
            }   
        }
		#endregion 
        #region 根据驾驶员证件号查找违规信息

        /// <summary>
        /// 根据UserID和车牌号查找违规信息
        /// </summary>
        /// <param name="drivercode">UserID</param>
        /// <returns>违规信息</returns>
        public static List<TbBstBreakRoleRec> SelectCarInfo(string userid,string carno)
        {
            List<TbBstBreakRoleRec> breaklist = new List<TbBstBreakRoleRec>();
            string sql = "select * from tb_bst_break_role_rec where user_id = :userid and CAR_NO = :carno";
            OracleParameter[] sp = { 
                                  new OracleParameter(":userid",userid),
                                  new OracleParameter(":carno",carno)
                                   };

            DataTable mes = OrclHelper.GetDT(sql, sp);
            if (mes != null && mes.Rows.Count > 0)
            {
                for (int i = 0; i < mes.Rows.Count; i++)
                {
                    TbBstBreakRoleRec breakInfo = new TbBstBreakRoleRec();
                    breakInfo.CarPkid = mes.Rows[i]["car_pkid"].ToString();
                    //breakInfo.UserId = mes.Rows[i]["USER_ID"].ToString();
                    breakInfo.DriverCode = mes.Rows[i]["driver_code"].ToString();
                    breakInfo.CarNo = mes.Rows[i]["car_no"].ToString();
                    breakInfo.CarType = mes.Rows[i]["car_type"].ToString();
                    breakInfo.BreakDate = Convert.ToDateTime(mes.Rows[i]["break_date"]);
                    breakInfo.BreakAddress = mes.Rows[i]["break_address"].ToString();
                    breakInfo.BreakType = mes.Rows[i]["break_type"].ToString(); 
                    breakInfo.BreakScore = mes.Rows[i]["break_score"].ToString();
                    breakInfo.BreakStatus = mes.Rows[i]["break_status"].ToString();
                    breakInfo.UpdateDate = Convert.ToDateTime(mes.Rows[i]["update_date"]);
                    breaklist.Add(breakInfo);
                }

            }
            return breaklist;
        }
        #endregion
    }
}
